package com.example.dotavideo;

import java.util.ArrayList;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.example.dotavideo.adapter.LeftMenuAdapter;
import com.example.dotavideo.base.DotaVideoApplication;
import com.example.dotavideo.bean.TypeBean;
import com.slidingmenu.lib.SlidingMenu;
import com.slidingmenu.lib.app.SlidingFragmentActivity;

public abstract class BaseActivity extends SlidingFragmentActivity {

  private ListView menuListView;
  private String title = "最近更新";
  public ArrayList<TypeBean> baseTypelist;
  private LeftMenuAdapter adapter;
private TextView tvDota1;
private TextView tvDota2;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // set the Behind View
    setBehindContentView(R.layout.left_menu);
    
    menuListView = (ListView) findViewById(R.id.lv_menu);
    
    tvDota1 = (TextView) findViewById(R.id.tv_dota1);
    tvDota2 = (TextView) findViewById(R.id.tv_dota2);
    
    tvDota1.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			tvDota1.setBackgroundColor(getResources().getColor(R.color.ccc));
			tvDota2.setBackgroundColor(getResources().getColor(R.color.title_bar));
			mainTypeChange(DotaVideoApplication.URL_TYPE_DOTA1);
		}
	});
    
    tvDota2.setOnClickListener(new OnClickListener() {
    	@Override
    	public void onClick(View v) {
    		tvDota1.setBackgroundColor(getResources().getColor(R.color.title_bar));
    		tvDota2.setBackgroundColor(getResources().getColor(R.color.ccc));
    		mainTypeChange(DotaVideoApplication.URL_TYPE_DOTA2);
    	}
    });
    
    
    menuListView.setOnItemClickListener(new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> paramAdapterView, View paramView, int paramInt,
          long paramLong) {
        getSlidingMenu().showContent();
        title = baseTypelist.get(paramInt).getTypeId();
        dataChange(title);
      }
    });
    
    
    findViewById(R.id.btn_today).setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View view) {
        getSlidingMenu().showContent();
        dataChange("-1");
      }
    });
    findViewById(R.id.btn_collection).setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View view) {
        getSlidingMenu().showContent();
        dataChange("我的收藏");
      }
    });
    
    
    // 自定义menu的效果
    SlidingMenu sm = getSlidingMenu();
    sm.setShadowWidthRes(R.dimen.shadow_width);
    sm.setShadowDrawable(R.drawable.shadow);
    sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    sm.setFadeDegree(0.15f);// 设置是否有阴影
    sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    sm.setBehindScrollScale(0);
    sm.setMode(SlidingMenu.LEFT);
    sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    
    
  }
  
  public void notifyChange(){
	  //baseTypelist = setMenuList();
	  adapter = new LeftMenuAdapter(this,baseTypelist);
	  menuListView.setAdapter(adapter);
	  //adapter.notifyDataSetChanged();
  }
  public abstract void dataChange(String id);
  public abstract void mainTypeChange(String url);
  
}
